package com.br.utilitarios;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class funcoes {
	
	String vUser;
	String vPass;
	
	private String geraMenuCalendario(int pQtd){
		String vJQuery = null;
		
		vJQuery  = "<script>\n";
		vJQuery += " $(function() {\n";        
		for (int i=1; i < pQtd+1; i++){
			if (i == 1){
				vJQuery += "    $( \"#txtData\" ).datepicker(\n";
			}else{	
				vJQuery += "    $( \"#txtData"+i+"\" ).datepicker(\n";
			}
			vJQuery += "            {       closeText: 'Fechar',\n";
			vJQuery += "                    prevText: '&#x3c;Anterior',\n";
			vJQuery += "                    nextText: 'Pr&oacute;ximo&#x3e;',\n";
			vJQuery += "                    currentText: 'Hoje',\n";
			vJQuery += "                    monthNames: ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho',\n";
			vJQuery += "                    'Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],\n";
			vJQuery += "                    monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun',\n";
			vJQuery += "                    'Jul','Ago','Set','Out','Nov','Dez'],\n";
			vJQuery += "                    dayNames: ['Domingo','Segunda-feira','Ter&ccedil;a-feira','Quarta-feira','Quinta-feira','Sexta-feira','Sabado'],\n";
			vJQuery += "                    dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'],\n";
			vJQuery += "                    dayNamesMin: ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'],\n";
			vJQuery += "                    weekHeader: 'Sm',\n";
			vJQuery += "                    dateFormat: 'dd/mm/yy',\n";
			vJQuery += "                    firstDay: 0,\n";
			vJQuery += "                    isRTL: false,\n";
			vJQuery += "                    showMonthAfterYear: false,\n";
			vJQuery += "                    yearSuffix: ''}\n";
			vJQuery += "    );\n";
		}	
		vJQuery += "  });\n"; 
		vJQuery += " \n";
		vJQuery += " $(document).ready(function () {\n";
		vJQuery += "  $(\"#metrobuttons\").AddMetroSimpleButton('bt1', 'metro-roxo', 'windows8/Style/Imagem/factory-64.png', 'Departamento', 'd01.jsp');\n";
		vJQuery += "  $(\"#metrobuttons\").AddMetroSimpleButton('bt2', 'metro-laranja', 'windows8/Style/Imagem/coins-64.png', 'Centro de Custo', 'cc01.jsp');\n";
		vJQuery += "  $(\"#metrobuttons\").AddMetroSimpleButton('bt3', 'metro-light_steel_blue', 'windows8/Style/Imagem/etiqueta.png', 'Etiquetas', 'et01.jsp');\n";
		vJQuery += "  $(\"#metrobuttons\").AddMetroSimpleButton('bt4', 'metro-LightSlateGray', 'windows8/Style/Imagem/documento.png', 'Documentos', 'doc01.jsp');\n";
		vJQuery += " });\n";
		
		vJQuery += "</script>\n";
				
		return vJQuery;
	}
	
	private String geraCalendario(int pQtd){
		String vJQuery = null;
		
		vJQuery  = "<script>\n";
		vJQuery += " $(function() {\n";        
		for (int i=0; i < pQtd; i++){
			if (i == 0){
				vJQuery += "    $( \"#txtData\" ).datepicker(\n";
			}else{	
				vJQuery += "    $( \"#txtData"+i+"\" ).datepicker(\n";
			}
			vJQuery += "            {       closeText: 'Fechar',\n";
			vJQuery += "                    prevText: '&#x3c;Anterior',\n";
			vJQuery += "                    nextText: 'Pr&oacute;ximo&#x3e;',\n";
			vJQuery += "                    currentText: 'Hoje',\n";
			vJQuery += "                    monthNames: ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho',\n";
			vJQuery += "                    'Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],\n";
			vJQuery += "                    monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun',\n";
			vJQuery += "                    'Jul','Ago','Set','Out','Nov','Dez'],\n";
			vJQuery += "                    dayNames: ['Domingo','Segunda-feira','Ter&ccedil;a-feira','Quarta-feira','Quinta-feira','Sexta-feira','Sabado'],\n";
			vJQuery += "                    dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'],\n";
			vJQuery += "                    dayNamesMin: ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'],\n";
			vJQuery += "                    weekHeader: 'Sm',\n";
			vJQuery += "                    dateFormat: 'dd/mm/yy',\n";
			vJQuery += "                    firstDay: 0,\n";
			vJQuery += "                    isRTL: false,\n";
			vJQuery += "                    showMonthAfterYear: false,\n";
			vJQuery += "                    yearSuffix: ''}\n";
			vJQuery += "    );\n";
		}	
		vJQuery += "  });\n";    
		vJQuery += "  </script>\n";
		
		return vJQuery;
	}
	
	private String geraMenu(){
		
		String vJQuery = null;
		
		vJQuery  = "<script type=\"text/javascript\">\n";
		vJQuery += " $(document).ready(function () {\n";
		vJQuery += "  $(\"#metrobuttons\").AddMetroSimpleButton('bt1', 'metro-roxo', 'windows8/Style/Imagem/factory-64.png', 'Departamento', 'd01.jsp');\n";
		vJQuery += "  $(\"#metrobuttons\").AddMetroSimpleButton('bt2', 'metro-laranja', 'windows8/Style/Imagem/coins-64.png', 'Centro de Custo', 'cc01.jsp');\n";
		vJQuery += "  $(\"#metrobuttons\").AddMetroSimpleButton('bt3', 'metro-light_steel_blue', 'windows8/Style/Imagem/etiqueta.png', 'Etiquetas', 'et01.jsp');\n";
		vJQuery += "  $(\"#metrobuttons\").AddMetroSimpleButton('bt4', 'metro-LightSlateGray', 'windows8/Style/Imagem/documento.png', 'Documentos', 'doc01.jsp');\n";
		vJQuery += " });\n";
		
		vJQuery += "</script>\n";
			
		return vJQuery;
	}

	private String geraMenuAdm(){
		
		String vJQuery = null;
		
		vJQuery  = "<script type=\"text/javascript\">";
		vJQuery += " $(document).ready(function () {";
		vJQuery += "  $(\"#metrobuttons\").AddMetroSimpleButton('bt1', 'metro-dark_slate_grey', 'windows8/Style/Imagem/codepen-01.png', 'Empresa', 'g01.jsp');";
		vJQuery += "  $(\"#metrobuttons\").AddMetroSimpleButton('bt2', 'metro-firebrick', 'windows8/Style/Imagem/organization-64.png', 'Cliente', 'e01.jsp');";
		vJQuery += "  $(\"#metrobuttons\").AddMetroSimpleButton('bt3', 'metro-dark_orchid', 'windows8/Style/Imagem/chn-wechat.png', 'Coligada', 'c01.jsp');";
		vJQuery += "  $(\"#metrobuttons\").AddMetroSimpleButton('bt4', 'metro-baker_chocolate', 'windows8/Style/Imagem/admin.png', 'Usuario', 'u01.jsp');";
		vJQuery += "  $(\"#metrobuttons\").AddMetroSimpleButton('bt5', 'metro-medium_spring_green', 'windows8/Style/Imagem/menu.png', 'Menu', 'mn01.jsp');";
		vJQuery += "  $(\"#metrobuttons\").AddMetroSimpleButton('bt6', 'metro-dark_cyan', 'windows8/Style/Imagem/privilegio.png', 'Privilegio', 'p00.jsp');";
		vJQuery += " });";
		vJQuery += "</script>";
			
		return vJQuery;
	}	
	
	private void gravaIniFile(){
		Properties prop = new Properties();  
		  
		try {  
			
			File vExists = new File("CONF-FILES/gesdoc.prop"); 
			//definir as propriedades e valores  
		    prop.setProperty("opacess", "DBUSER");  
		    prop.setProperty("opass", "IFADM13*");  
		  
		    //salvar o arquivo 
		    if (vExists.exists()){
		    	
		    }else{	
		    	prop.store(new FileOutputStream("CONF-FILES/gesdoc.prop"), null);
		    }
		  
		} catch (IOException ex) {  
		    ex.printStackTrace();  
		}
	}
	
	private void lerIniFile(){
		
		Properties prop = new Properties();  
		
		try {  
		    
		    //carrega properties 
			prop.load(new FileInputStream("gesdoc.prop"));  
		  
		    //recupera e imprime valores  
		    this.vUser = prop.getProperty("opacess");  
		    this.vPass = prop.getProperty("opass");  
		    System.out.println("Carregou : "+this.vUser+" - "+this.vPass);
		} catch (IOException ex) {  
		    ex.printStackTrace();  
		}  
	}
	
	public String getUser(){
		lerIniFile();
		return this.vUser;
	}
	
	public String getPass(){
		lerIniFile();
		return this.vPass;
	}
	
	public String getJQuery(){
		return geraMenu();
	}
	
	public String getJQueryAdm(){
		return geraMenuAdm();
	}	
	
	public String getCalendar(int pQtd){
		return geraCalendario(pQtd);
	}
	
	public String getMenuCalendario(int pQtd){
		return geraMenuCalendario(pQtd);
	}
}
